<%@page import="systems.Recently"%>
<%@page import="helpers.LanguageHelper"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="systems.RecentlyTag"%>
<%@page import="helpers.DateHelper"%>
<%@page import="entities.ArticleSearch"%>
<%@page import="entities.Article"%>
<%@page import="models.CategoryModel"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%
CategoryModel categoryModel = CategoryModel.getInstance();
List<Category> categories = categoryModel.getAll();
List<Article> articles = Recently.getArticles("", "lastest_article");
List<String> tags = RecentlyTag.getTags();
String hasArchives = (String) request.getParameter("hasArchives");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
				
				<div class="span4 slidebar">
					<div class="search widget">
						<form  method="get" action="/search">
							<input type="text" name="q" placeholder="Search article" >
						</form>
					</div>
					
					<% if (hasArchives != null) { %>
	            	<%
	            	Calendar cal = Calendar.getInstance();
	            	int currentYear = cal.get(Calendar.YEAR);
	            	int year = currentYear;
	            	int month = cal.get(Calendar.MONTH)+1;
	            	int countMonth = DateHelper.getCountMonthFromNow(1, 2013);
	            	%>
					<div class="widget archives">
						<div class="title"><h3>Archives</h3></div>
						<div class="row-fluid">
							<div class="span6">
								<h3><%=year %></h3>
								<ul>
									<%
			                    	for (int i = 0; i < countMonth + 1; i++) {
			                    		//if (currentYear - year > 1) break;
			                    	%>
									<li><a href="/archives/<%=month <10 ? "0" + month : month %>-<%=year%>"><%=DateHelper.getMonthName(month-1) %>&nbsp;<%=year %></a></li>
									<%
			                        	month -= 1;
			                			if (month <= 0) {
			                				month = 12;
			                				year -= 1;
			                				if (i < countMonth) {
			                			%>
			             		</ul>
							</div>
			             	<div class="span6">
								<h3><%=year %></h3>
								<ul>
			             			<li><span><%=year %></span></li>
			                				<%
			                				}
			                			}
                        			} %>
								</ul>
							</div>
						</div>
						
					</div>
					<% } %>
					
					<div class="widget">
						<div class="title"><h3>Recent Posts</h3></div>
						<ul class="arrow_list">
							<% 
                    		for (int i = 0; i < articles.size(); i++) {
                    			if (i > 5) break;
                    		%>
							<li><a href="/article/<%=articles.get(i).getAlias() %>"><%=articles.get(i).getTitle() %></a></li>
							<% } %>
						</ul>
					</div>
					
					<div class="widget">
						<div class="title"><h3>Category</h3></div>
						<ul class="links-list-alt">
							<% for (int i = 0 ; i < categories.size(); i++ ) { %>
							<li><a href="/category/<%=categories.get(i).getAlias() %>"><%=categories.get(i).getName() %></a></li>
							<% } %>
						</ul>
					</div>
				
					<div class="widget">
						<div class="title"><h3>Tags</h3></div>
						<div class="tags">
							<%
	                    	for (int i = 0; i < tags.size(); i++) {
	                    		if (i > 50) break;
	                    	%>
							<a href="/tag/<%=URLEncoder.encode(tags.get(i))%>"><%=tags.get(i) %></a>
							<% } %>
						</div>
					</div>
				</div>